#include "AST_process.h"

void process_funcFParams(ASTNode* node, vector<pair<string, string>> &paramNames){
    if (!node) return;
    
    for(auto child : node->children) {
        
        if (child->type == "funcFParam") {
            // 处理函数参数
            string type;
            visitBType(node, type);

            string var_name;
            visitIdent(node, var_name);

            paramNames.push_back(make_pair(type, var_name));
            
        }
        if(child->type == "argFunctionF"){
            process_funcFParams(child, paramNames);
        }
    }
}

void process_blockItem(ASTNode* node, SymbolTable* s, Module* m, BasicBlock* bb) {
    if (!node) return;

    for (auto child : node->children) {
        if (child->type == "blockItem"){
            process_blockItem(child, s, m, bb);
        }
        else if (child->type == "decl") {
            process_decl(child, s, m, bb);
        }
        else if (child->type == "stmt") {
            process_stmt(child, s, m, bb);
        }
    }
}

void process_decl(ASTNode* node, SymbolTable* s, Module* m, BasicBlock* bb) {
    if (!node) return;

    for (auto child : node->children) {
        if (child->type == "varDecl") {
            // 处理变量声明(局部变量)
            visitInitVarDef(child, s, m, bb, false, false);
        }
    }
}

void process_stmt(ASTNode* node, SymbolTable* s, Module* m, BasicBlock* bb) {
    if (!node) return;

    for (auto child : node->children) {
        if (child->type == "exp") {
            process_exp(child, s, m, bb);
        }
        else if (child->type == "return") {
            process_return(child, s, m, bb);
        }

    }
}

void process_exp(ASTNode* node, SymbolTable* s, Module* m, BasicBlock* bb) {
    if (!node) return;

    for (auto child : node->children) {
        if (child->type == "assignExp") {
            // 处理赋值表达式
            // visitAssignExp(child, s, m, bb);
        }
    }
}

void process_return(ASTNode* node, SymbolTable* s, Module* m, BasicBlock* bb) {
    if (!node) return;

    for (auto child : node->children) {
        if (child->type == "argExp") {
            // 处理返回值
            // visitReturn(child, s, m, bb);
        }
    }
}